const app = getApp()
// var data_false = require('../../utils/data.js');
// console.log(data_false);
Page({
  data: {
    phone_data: '父组件数据'
  },
  init() {
    this.setData({
      list_data: [],
      loading: true,
      currentPage: 1,
      page_num: 6,
      loading: true,
      load_more: false,
      all_over: false
    });
  },
  onPullDownRefresh() {
    this.init();
    this.getList();
  },
  loadMore() {
    if (this.data.load_more){
      return;
    }
    if (this.data.currentPage == this.data.totalPages) {
      return;
    } else {
      this.setData({
        load_more: true
      });
      this.data.currentPage += 1;
      this.getList();
    }
  },
  getList() {
    let self = this;
    wx.request({
      url: 'https://aweakcoder.natapp4.cc/home/user',
      method: 'get',
      data: {
        page: self.data.currentPage,
        num: self.data.page_num
      },
      success: function (data) {
        console.log(1);
        if (data.statusCode == 200) {
          data = data.data.data;
          var all_over = false;;
          if (data.currentPage == data.totalPages) {
            all_over = true;
          }
          var list_data;
          if (data.currentPage==1){
            list_data = data.data
          }else{
            list_data = self.data.list_data.concat(data.data);
          }
          setTimeout(function () {
            self.setData({
              list_data: list_data,
              currentPage: data.currentPage,
              totalPages: data.totalPages,
              all_over: all_over,
              load_more: false
            }, () => {
              console.log('赋值成功')
            });
          }, 500)
        }
      },
      fail: function (e) {
        // console.log(e);
        // self.setData({ list_data: data_false })
      },
      complete: function (e) {
        wx.stopPullDownRefresh();
        setTimeout(function () {
          self.setData({
            loading: false
          });
        }, 800)

        // console.log(e);
      }
    });
  },
  onLoad: function () {
    let self = this;
    self.onPullDownRefresh();
    // console.log('代码片段是一种迷你、可分享的小程序或小游戏项目，可用于分享小程序和小游戏的开发经验、展示组件和 API 的使用、复现开发问题和 Bug 等。可点击以下链接查看代码片段的详细文档：')
    // console.log('https://mp.weixin.qq.com/debug/wxadoc/dev/devtools/devtools.html');
    console.log('-------' + this.data.page_num);
  },
  onGetCode: function (e) {
    this.setData({
      code: e.detail.val
    });
  }



  // https://wake.nat300.top/home/user

})